#include <iostream>
#include <pthread.h>
#include <cstring>
#include <cerrno>
#include <unistd.h>
#include <sys/types.h>

using namespace std;

int g_val = 100;

void *threadRoutines(void *args)
{
    while(true)
    {
        cout << "new thread: " << getpid() << g_val << " &: " << &g_val << endl;
        sleep(1);
    }
}

int main1()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, threadRoutines, (void *)"thread 1");

    while(true)
    {
        cout << "main thread: " << getpid() << g_val << " &: " << &g_val << endl;
        sleep(100);
        break;
    }

    int n = pthread_join(tid, nullptr);
    cout << "n: " << n << "errstring: " << strerror(n) << endl;

    return 0;
}